package com.cn.lyl.lawyer.controller;

import com.cn.lyl.lawyer.model.entity.LeavingModel;
import com.cn.lyl.lawyer.service.LeavingService;
import com.cn.lyl.lawyer.util.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/back/leaving")

public class LeavingController {
    @Autowired
    private LeavingService leavingService;
    @PostMapping("/add")
    public Object add(LeavingModel leavingModel){
        leavingService.add(leavingModel);
        return CommonResult.success(null);
    }
    @PostMapping("/delete")
    public Object delete(Integer id){
        leavingService.delete(id);
        return CommonResult.success(null);
    }
    @PostMapping("/findAll")
    public Object findAll(LeavingModel leavingModel){
        List<LeavingModel> all = leavingService.findAll(leavingModel);
        Map map = new HashMap();
        map.put("count",leavingService.getCount(leavingModel));
        map.put("list",all);
        return CommonResult.success(map);
    }
    @PostMapping("/findById")
    public Object findById(Integer id){
        LeavingModel info = leavingService.findInfo(id);
        return CommonResult.success(info);
    }
}
